﻿using System;
using System.Text;
using System.Data;

using LTJ.Common.Generic;
using LTJ.Entity;
using LTJ.Common;
using LTJ.Config;

namespace LTJ.Data.DataProvider
{
    /// <summary>
    /// 企业信息数据操作
    /// </summary>
    public class Companys
    {
        /// <summary>
        /// 创建企业信息
        /// </summary>
        public static int CreateCompany(CompanyInfo cinfo)
        {
            return DatabaseProvider.GetInstance().CreateCompany(cinfo);
        }

        /// <summary>
        /// 根据查询条件获取企业数量
        /// </summary>
        public static int GetCompanyCountByCondition(string querystring)
        {
            return DatabaseProvider.GetInstance().GetCompanyCountByCondition(querystring);
        }

        /// <summary>
        /// 企业数据分页操作
        /// </summary>
        public static DataTable GetCompanyPageList(int pageindex, int pagesize, string conditions,string orderstr)
        {
            return DatabaseProvider.GetInstance().GetCompanyPageList(pageindex, pagesize, conditions, orderstr);
        }
        /// <summary>
        /// 获取企业信息
        /// </summary>
        public static CompanyInfo GetCompanyInfo(int id)
        {
            return LoadSingleCompanyInfo(DatabaseProvider.GetInstance().GetCompanyByID(id));
        }

        /// <summary>
        /// 更新企业信息
        /// </summary>
        public static void UpdateCompany(CompanyInfo cinfo)
        {
            DatabaseProvider.GetInstance().UpdateCompany(cinfo);
        }


        /// <summary>
        /// 删除企业信息
        /// </summary>
        /// <param name="ids">企业id组合</param>
        /// <returns></returns>
        public static int DelCompany(string ids)
        {
            return DatabaseProvider.GetInstance().DelCompany(ids);
        }

        /// <summary>
        /// 判断企业是否存在
        /// </summary>
        public static int IsExistCompany(string companyname)
        {
            return DatabaseProvider.GetInstance().IsExistCompany(companyname);
        }

        /// <summary>
        /// 更改企业状态
        /// </summary>
        public static bool UpdateCorpStatus(string ids, int status)
        {
            return DatabaseProvider.GetInstance().UpdateCorpStatus(ids, status);
        }
        /// <summary>
        /// 设置企业积分
        /// </summary>
        public static int SetCorpScore(int cid, int scores)
        {
            return DatabaseProvider.GetInstance().SetCorpScore(cid, scores);
        }

        #region help
        public static CompanyInfo LoadSingleCompanyInfo(IDataReader reader)
        {
            CompanyInfo _info = null;
            if (reader.Read())
            {
                _info = new CompanyInfo();
                _info.id = TypeConverter.StrToInt(reader["id"].ToString());
                _info.cname = reader["cname"].ToString();
                _info.ecname = reader["ecname"].ToString();
                _info.logo = reader["logo"].ToString();
                _info.welcome = reader["welcome"].ToString();
                _info.relater = reader["relater"].ToString();
                _info.relateform = reader["relateform"].ToString();
                _info.bio = reader["bio"].ToString();
                _info.status = TypeConverter.StrToInt(reader["status"].ToString());
                _info.Manager = TypeConverter.StrToInt(reader["manager"].ToString(), 0);
                _info.Authoritys = reader["authoritys"].ToString();
                _info.Phone = reader["phone"].ToString();
                _info.Scores = TypeConverter.StrToInt(reader["scores"].ToString(), 0);
                _info.Mains = reader["main"].ToString();
                _info.CreateDate = Utils.GetStandardDateTime(reader["createdate"].ToString());
                _info.Creater = reader["creater"].ToString();
                _info.Email = reader["email"].ToString();
                _info.WebUrl = reader["weburl"].ToString();
                _info.MSN = reader["msn"].ToString();

                _info.mcount = TypeConverter.StrToInt(reader["mcount"].ToString(), -1);
                _info.ucount = TypeConverter.StrToInt(reader["ucount"].ToString(), -1);
            }
            reader.Close();
            return _info;
        }
        #endregion
    }
}
